#include "logindialog.h"
#include <QMessageBox>
#include <QSqlQuery>
#include "sqlmanage.h"
#include <QCryptographicHash>

LoginDialog::LoginDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LoginDialog)
{
    ui->setupUi(this);
    ui->login->setDefault(true);
    //connect(ui->login,&QPushButton::clicked,this,&LoginDialog::on_login_clicked);
    connect(ui->exit,&QPushButton::clicked,this,&LoginDialog::close);
    setWindowFlags(windowFlags()& ~Qt::WindowMaximizeButtonHint);
    setFixedSize(this->width(), this->height());
}

LoginDialog::~LoginDialog()
{
    //qDebug()<<"LoginDialog 资源释放";
    delete ui;
}

void LoginDialog::on_login_clicked()
{
       /*if(ui->login_2->text().isEmpty())
       {
           QMessageBox::information(this,tr("请输入用户名"),tr("请输入用户名再登录！"),QMessageBox::Ok);
           ui->login_2->setFocus();
       }
       else if(ui->password->text().isEmpty())
       {
           QMessageBox::information(this,tr("请输入密码"),tr("请输入密码再登录！"),QMessageBox::Ok);
           ui->password->setFocus();
       }
       if(!(ui->login_2->text().isEmpty())&&!(ui->password->text().isEmpty()))
       {    QString pwdmd5 = ui->password->text();
            QByteArray bb = pwdmd5.toLatin1();
            bb = QCryptographicHash::hash (bb, QCryptographicHash::Md5 );
            pwdmd5 = bb.toHex();
            //qDebug()<<pwdmd5;
            QString id = ui->login_2->text();
            SqlManage conn;
            QSqlQuery query;
            query.exec(QString("select pwd from password where id='%1'").arg(id));
            query.next();
            if(query.value("pwd").toString() == pwdmd5)
            {*/
                QDialog::accept();
            /*}
            else
            {
                QMessageBox::warning(this,tr("用户名或密码错误"),tr("请输入正确的用户名和密码！"),QMessageBox::Ok);
                ui->login_2->clear();
                ui->password->clear();
                ui->login_2->setFocus();
            }
            conn.closeSql();
       }*/
}
